<?php
if ( count( get_included_files() ) == 1 ) die( '---' );

class Masque
{
	function Masque()
	{
		global $C2iDefaut;

		$this->competenceId = '';
		$this->referentiel = $C2iDefaut;
		$this->course_code = '';
		$this->titre = '';
		$this->validationAuto = 0;

		$tbl_masque = claro_sql_get_tbl('C2IPRATmasque');
		$this->tableMasque = $tbl_masque['C2IPRATmasque'];
	}

	function load()
	{
		$sql = "SELECT * 
			FROM `".$this->tableMasque."` 
			WHERE competenceId = '".$this->competenceId."'
			AND referentiel = '".$this->referentiel."'
			AND course_code = '".$this->course_code."'";
		$data = claro_sql_query_get_single_row($sql);

	   if( !empty($data) )
	   {
		$this->competenceId = $data['competenceId'];
		$this->referentiel = $data['referentiel'];
		$this->course_code = $data['course_code'];
		$this->titre = $data['titre'];
		$this->validationAuto = $data['validationAuto'];
	   	
	   	return true;
	   }
	   else
	   return false;
	}

	function save()
	{
		$sql = "INSERT INTO `".$this->tableMasque."`
			SET competenceId = '".$this->competenceId."',
			    referentiel = '".$this->referentiel."',
			    course_code = '".$this->course_code."',
			    titre = '".$this->titre."',
			    validationAuto = '".$this->validationAuto."'";
		if( claro_sql_query($sql) == false ) return false;	

		return true;
	}	

	function delete()
	{
		$sql = "DELETE FROM `".$this->tableMasque."` 
			WHERE competenceId = '".$this->competenceId."'
			AND referentiel = '".$this->referentiel."'
			AND course_code = '".$this->course_code."'";
		if( claro_sql_query($sql) == false ) return false;	

		return true;
	}

	function chercherListeMasques()
	{
		$sql = "SELECT DISTINCT course_code
			FROM `".$this->tableMasque."`";
		return claro_sql_query_fetch_all($sql);
	}

	function chercherListeCompetencesAuto()
	{
		$sql = "SELECT competenceId
			FROM `".$this->tableMasque."`
			WHERE course_code = '".$this->course_code."'
			AND validationAuto = 1";
		return claro_sql_query_fetch_all($sql);
	}

	function deleteCourse()
	{
		$sql = "DELETE FROM `".$this->tableMasque."` 
			WHERE course_code = '".$this->course_code."'";
		if( claro_sql_query($sql) == false ) return false;	

		return true;
	}

	/**
     * get competenceId
     *
     * @author Pierre Raynaud
     * @return competenceId
     */
	function getCompetenceId()
	{
		return (int) $this->competenceId;
	}
	
	/**
     * set competenceId
     *
     * @author Pierre Raynaud
     * @param int $value
     */
	function setCompetenceId($value)
	{
		$this->competenceId = $value;
	}

	/**
     * get referentiel
     *
     * @author Pierre Raynaud
     * @return referentiel
     */
	function getReferentiel()
	{
		return $this->referentiel;
	}
	
	/**
     * set referentiel
     *
     * @author Pierre Raynaud
     * @param $value
     */
	function setReferentiel($value)
	{
		$this->referentiel = $value;
	}

	/**
     * get course_code
     *
     * @author Pierre Raynaud
     * @return course_code
     */
	function getCourseCode()
	{
		return $this->course_code;
	}
	
	/**
     * set course_code
     *
     * @author Pierre Raynaud
     * @param $value
     */
	function setCourseCode($value)
	{
		$this->course_code = $value;
	}

	/**
     * get titre
     *
     * @author Pierre Raynaud
     * @return course_code
     */
	function getTitre()
	{
		return $this->titre;
	}
	
	/**
     * set titre
     *
     * @author Pierre Raynaud
     * @param $value
     */
	function setTitre($value)
	{
		$this->titre = $value;
	}

	/**
     * get validationAuto
     *
     * @author Pierre Raynaud
     * @return course_code
     */
	function getValidationAuto()
	{
		return $this->validationAuto;
	}
	
	/**
     * set validationAuto
     *
     * @author Pierre Raynaud
     * @param $value
     */
	function setValidationAuto($value)
	{
		$this->validationAuto = $value;
	}
}

?>
